#%%
import numpy as np 
from types import FunctionType

__all__=(
    "LossFunc",
    "sse"
)

# 损失函数
class LossFunc:
    def __init__(self,f:FunctionType,f_derivate:FunctionType):
        self.f = f 
        self.f_derivate = f_derivate

    def __call__(self,label,predict):
        return self.f(label,predict)

    def derivate(self,label,predict):
        return self.f_derivate(label,predict)

# sse
def f_sum_of_squared_error(label,predict):
    return (label-predict)**2

def f_sum_of_squared_error_derivate(label,predict):
    return 2*(predict-label)

# 平方和误差
sse = LossFunc(
    f_sum_of_squared_error,
    f_sum_of_squared_error_derivate
)

